package com.kmproject.haifu.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.kmproject.haifu.mvp.contract.RentSeekingListContract;
import com.kmproject.haifu.mvp.model.api.service.UserService;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.RentSeekingDetail;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 08/12/2019 17:51
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class RentSeekingListModel extends BaseModel implements RentSeekingListContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;
    private UserService userService;

    @Inject
    public RentSeekingListModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
        userService = repositoryManager.obtainRetrofitService(UserService.class);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<ResultBean<List<HousePayWayBean>>> getAreaTree(String url, String value, String category) {
        return userService.getAreaTree(url, value, category);
    }

    @Override
    public Observable<ResultBean<List<HousePayWayBean>>> getReleaseType(String value) {
        return userService.dictListForSeekingPublishType(value);
    }

    @Override
    public Observable<ResultBean<List<HousePayWayBean>>> getPrice(String value) {
        return userService.dictListForSeekingPublishType(value);
    }

    @Override
    public Observable<ResultBean<List<RentSeekingDetail>>> getRentSeekingList(Map<String, Object> maps) {
        return userService.getHouseRentSeekingList(creatRequestBody(maps, mGson));
    }

    @Override
    public Observable<ResultBean> delete(String seekingId) {
        Long[] ids = {Long.parseLong(seekingId)};
        Map<String, Object> maps = new HashMap<>();
        maps.put("seekingIds", Arrays.asList(ids));
        return userService.deleteRentSeeking(creatRequestBody(maps, mGson));
    }
}